import React,{PropTypes,Component,PureComponent}  from 'react';
import {Select ,Button ,Tree ,Modal, Form, Input,Row,Col,message } from 'antd';



const TNode = Tree.TreeNode;
// 方案指标 树形图
const treeData = [
  {
    title: '基本信息',
    key:'0',
    children: [
      {
        title: '投资策略',
        type: 'choice',
        key: 'investStrategy',
      },
      {
        title: '成立年限',
        type: 'choice',
        key: 'establishAge',
      },
      {
        title: '状态',
        type: 'choice',
        key: 'status',
      },
      {
        title: '基金规模',
        type: 'choice',
        key: 'fundScale',
      },
    ]
  },
  {
    title: '收益率',
    key:'1',
    children: [
      {
        title: '年化收益',
        type: 'range',
        key: 'annualYieldRate',
      },
    ]
  },
  {
    title: '风险调整收益',
    key:'2',
    children: [
      {
        title: 'Alpha',
        type: 'range',
        key: 'alpha',
      },
      {
        title: 'Sharpe',
        type: 'range',
        key: 'sharpeRatio',
      },
      {
        title: 'Treynor',
        type: 'range',
        key: 'treynorRatio',
      },
      {
        title: 'IR',
        type: 'range',
        key: 'informationRatio',
      },
      {
        title: 'Sortino',
        type: 'range',
        key: 'sortinoRatio',
      },
      {
        title: 'M2',
        type: 'range',
        key: 'm2',
      },
      {
        title: 'Calmar',
        type: 'range',
        key: 'calmarRatio',
      },
    ]
  },
  {
    title: '风险分析',
    key:'3',
    children: [
      {
        title: 'VAR',
        type: 'range',
        key: 'var',
      },
      {
        title: '波动率',
        type: 'range',
        key: 'volatility',
      },
      {
        title: 'CTE',
        type: 'range',
        key: 'cte',
      },
      {
        title: 'TE',
        type: 'range',
        key: 'te',
      },
      {
        title: 'Beta',
        type: 'range',
        key: 'beta',
      },
      {
        title: '最大回撤',
        type: 'range',
        key: 'maxDrawdown',
      },
    ]
  }
]

export default class SchemeKpi extends React.Component {
  state = {
    expandedKeys: [],//展开指定的树节点
    autoExpandParent: true,//是否自动展开父节点
    checkedKeys: [],//受控父子节点关联
    selectedKeys: [],//设置选中的树节点
  }
  //展开收起节点时触发
  onExpand = (expandedKeys) => {
    console.log('onExpand', arguments);
    this.setState({
      expandedKeys,
      autoExpandParent: false,
    });
  }
  //点击复选框触发
  onCheck = (checkedKeys) => {
    const {  checkkpi } = this.props;
    if(this.props.sfschemeid == 1 && this.props.sfschemename == '默认方案'){
      message.warning('默认方案禁止操作');
      return;
    }

    if(this.props.sfschemeid && this.props.sfschemename){
      this.setState({ checkedKeys });
      checkkpi.push(checkedKeys);
    }else{
      message.warning('请选择方案');
    }

  }
  // 点击树节点触发
  onSelect = (selectedKeys, info) => {
    console.log('onSelect', info);
    this.setState({ selectedKeys });
  }
  renderTreeNodes = (data) => {
    return data.map((item) => {
      if (item.children) {
        return (
          <TNode title={item.title} key={item.key} dataRef={item}>
            {this.renderTreeNodes(item.children)}
          </TNode>
        );
      }
      return <TNode {...item} />;
    });
  }
  componentWillMount(){
    const sfkpiName = this.props.sfkpiName;
    this.setState({
      checkedKeys:sfkpiName,
      expandedKeys:sfkpiName
    })
  }
  componentWillReceiveProps(nextProps){
    const sfkpiName = nextProps.sfkpiName;
    this.setState({
      checkedKeys:sfkpiName,
      expandedKeys:sfkpiName
    })
    if(sfkpiName == undefined){
      this.setState({
        checkedKeys:[],
        expandedKeys:[]
      })
    }
  }
  render() {
    const {fliterlist} = this.props;
    return (
      <Tree
        checkable
        onExpand={this.onExpand}
        expandedKeys={this.state.expandedKeys}
        autoExpandParent={this.state.autoExpandParent}
        onCheck={this.onCheck}
        checkedKeys={this.state.checkedKeys}
        onSelect={this.onSelect}
        selectedKeys={this.state.selectedKeys}
      >
        {this.renderTreeNodes(treeData)}
      </Tree>
    );
  }
}
